/*
 * @Author: 何善万 swhe@che300.com
 * @Date: 2024-08-16 15:11:34
 * @LastEditors: 何善万 swhe@che300.com
 * @LastEditTime: 2024-08-19 09:38:34
 * @FilePath: \my-notion-redux\src\redux\slices\commonFuns.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createSlice } from '@reduxjs/toolkit';

const commonFunsSlice = createSlice({
  name: 'commonFunsSlice',
  initialState: {
    navigate: null,
    changeLanguage: null,
    setThemeColor: null
  },
  reducers: {
    setCommonFunc: (state, { payload }) => {
      if (Object.prototype.toString.call(payload) === '[object Object]' && Object.keys(payload).length > 0) {
        for (const item in payload) {
          state[item] = payload[item];
        }
      } else {
        throw Error('payload must be an object!');
      }
    }
  }
});

export const { setCommonFunc } = commonFunsSlice.actions;
export default commonFunsSlice.reducer;
